#!/bin/sh
# func:清除ssh隧道
# author:reed
# date:12/09/2012
#
# 定义环境变量
# destorySSHTunnel.sh 本地端口
# destorySSHTunnel.sh localPort

localPort=$1
operateLog="/tmp/destorySSHTunnel.log"
if [ -z "$localPort" ]; then
    echo "port is empty"
    return 1
fi

#删除本地ssh隧道 
ssh_pid=$(netstat -tlnp |grep sshd| grep 0.0.0.0:$localPort |awk '{print $7}' | awk 'BEGIN {FS="/"} {print $1}')
if [ ! -z "${ssh_pid}" ]; then 
    kill -9 ${ssh_pid}
    echo "kill -9 ${ssh_pid}" >> $operateLog
fi

